<HEAD> <TITLE> Profiling </TITLE> </HEAD> <BODY BACKGROUND=http://www.imaginary.com/~beek/gifs/bg.jpg TEXT=#000000 ALINK=#FFFF00 VLINK=#550000 LINK=#000099> <center> <H1> Profiling </H1> </center>
<p>
Doing CPU profiling is actually quite simple; all you have to do is compile
with PROFILE_FUNCTIONS turned on, and then use the function_profile() efun.
That efun will return the number of times each function in the mudlib
is called, the ammount of CPU time spent in the function, and the ammount
of CPU time spent in functions called by that function.
<p>
Note that these efuns are useless on some systems since the timer isn't
accurate enough.  However, where it is available, one can write a routine
which examines the info and constructs a very accurate picture of how
the CPU time is being spent; here is a simple example of how to tally it
by object (note: you'll have to rewrite it the old way if you don't have
<A HREF=http://www.imaginary.com/~beek/mudos/lpc/foreach.html>  foreach </A> or the new <A HREF=http://www.imaginary.com/~beek/mudos/lpc/function.html>  function </A> type):
<p>
<pre>
int total(mapping *info) {
    int ret;
    mapping item;
<p>
    foreach (item in info)
        ret += item["self"];
    return ret;
}
<p>
void top_list() {
    mixed *tmp;
    int i, j;
<p>
    tmp = map(objects((: !clonep($1) :)),
              (: ({ $1, total(function_profile($1)) }) :));
    // We could use sort_array() here, but that's an inefficient way
    // to get the top 10 when there are lots of objects.
<p>
    for (i = 0; i < 10; i++) {
        mixed foo;
<p>
	for (j = i; j < sizeof(tmp); j++)
	    if (tmp[i][1] < tmp[j][1]) {
		foo = tmp[i];
		tmp[i] = tmp[j];
		tmp[j] = foo;
	    }
	printf("%60-O %i\n", tmp[i][0], tmp[i][1]);
    }
}
</pre>
<p>
Similar routines can be written to examine specific functions, etc.
<p>
If your concern is memory, look at the mud_status(0) output; that will
give you a general idea of where the memory is being used:
<p>
<DT>
<DT> <IMG SRC = http://www.imaginary.com/Graphics/Whiteball.gif> Sentences: used by add_action() and call_outs().  Typically, these take
up an insignificant amount of space, even on large MUDs.
<DT> <IMG SRC = http://www.imaginary.com/Graphics/Whiteball.gif> Objects: The space used by objects and their global variables (although
not by the values in those variables)
<DT> <IMG SRC = http://www.imaginary.com/Graphics/Whiteball.gif> Arrays and Mappings: The ammount of memory used by allocated arrays and mappings.
<DT> <IMG SRC = http://www.imaginary.com/Graphics/Whiteball.gif> Interactives: The space used storing information about users.  Should also be quite small.
<DT> <IMG SRC = http://www.imaginary.com/Graphics/Whiteball.gif> Strings: The ammount of space used by strings.  Note that the which strings are counted by this varies with driver version, so later versions will report more string memory allocated despite the fact that the ammount of memory taken up by strings is actually less; this is due to the fact that one type of strings are not counted in the older drivers.
<DT> <IMG SRC = http://www.imaginary.com/Graphics/Whiteball.gif> call out: The space used managing call outs.
<DT> <IMG SRC = http://www.imaginary.com/Graphics/Whiteball.gif> Prog blocks: The space used storing program code.  If this is unreasonably large, one might want to look at using replace_program().
</DT>
<p>
<HR> <ADDRESS> <A HREF=http://wagner.princeton.edu/~tim>  Tim Hollebeek </A> <p> <A HREF="http://www.imaginary.com/~beek/">  Beek </A>@ZorkMUD, Lima Bean, IdeaExchange, TMI-2, and elsewhere </ADDRESS>
